package mytest;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import net.sourceforge.opencamera.R;

import java.util.ArrayList;
import java.util.List;


public class AllPhotosFragment extends Fragment {

    private RecyclerView recyclerView;
    private PhotoAdapter photoAdapter;
    private List<String> allPhotos = new ArrayList<>(); // 假设我们有图片路径列表

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_all_photos, container, false);

        recyclerView = view.findViewById(R.id.recyclerViewAllPhotos);
        recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 3));  // 3列网格

        loadAllPhotos();  // 加载图片数据

        photoAdapter = new PhotoAdapter(getContext(), allPhotos);
        recyclerView.setAdapter(photoAdapter);

        return view;
    }

    private void loadAllPhotos() {
        // 从设备加载所有照片，按时间顺序排列
        // 模拟添加数据
        allPhotos.add("/path/to/photo1.jpg");
        allPhotos.add("/path/to/photo2.jpg");
        // 更多数据...
    }
}
